package com.example.smartlearning.controller;


import com.example.smartlearning.service.impl.NewServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;


@CrossOrigin//跨域
@RestController//遵循RestFul
@RequestMapping("/Smart/New/")
public class NewController {

    @Resource
    NewServiceImpl newService;

    /**
     * 查询所有新闻
     *
     * @param start 开始
     * @param limit 条数
     * @return 返回
     */
    @GetMapping("selectAllNews")
    public String selectAllNews(@RequestParam("start") int start, @RequestParam("limit") int limit) {
        return newService.selectAllNews(start, limit);
    }


    /**
     * 根据用户的兴趣查询新闻
     *
     * @param interest 兴趣
     * @return 返回
     */
    @GetMapping("selectByUser")
    public String selectByUser(@RequestParam("interest") String interest) {
        return newService.selectByUser(interest);
    }

    /**
     * @param newId 新闻id
     * @return 返回
     */
    @GetMapping("selectNewDetail")
    public String selectNewDetail(@RequestParam("newId") int newId) {
        return newService.selectNewDetail(newId);
    }

    /**
     * 根据id更新新闻
     *
     * @param newId      id
     * @param newTitle   标题
     * @param newDetail  详情
     * @param createTime 创建时间
     * @param newSort    分类
     * @param newInImg   详情图片
     * @param newImg     封面图片
     * @return 返回
     */
    @PostMapping("updateNewById")
    public String updateNewById(
            @RequestParam("newId") int newId,
            @RequestParam("newTitle") String newTitle,
            @RequestParam("newDetail") String newDetail,
            @RequestParam("createTime") String createTime,
            @RequestParam("newSort") String newSort,
            @RequestParam("newInImg") String newInImg,
            @RequestParam("newImg") String newImg) {
        return newService.updateNewById(newId, newTitle, newDetail, createTime, newSort, newInImg, newImg);
    }

    /**
     * @param newTitle   标题
     * @param newDetail  详情
     * @param createTime 创建时间
     * @param newSort    分类
     * @param newUser    用户
     * @param newInImg   详情图片
     * @param newImg     封面图片
     * @return 返回
     */
    @PostMapping("addNew")
    public String addNew(
            @RequestParam("newTitle") String newTitle,
            @RequestParam("newDetail") String newDetail,
            @RequestParam("createTime") String createTime,
            @RequestParam("newSort") String newSort,
            @RequestParam("newUser") int newUser,
            @RequestParam("newInImg") String newInImg,
            @RequestParam("newImg") String newImg) {
        return newService.addNew(newTitle, newDetail, createTime, newSort, newUser, newInImg, newImg);
    }

    /**
     * 删除新闻
     *
     * @param id id
     * @return 返回
     */
    @PostMapping("deleteByNewId")
    public String deleteByNewId(@RequestParam("id") int id) {
        return newService.deleteByNewId(id);
    }

}
